<?php 
echo $javascript->codeBlock("

				var sherhMap = {
					init: function(tapMapID){
						if (GBrowserIsCompatible()) {
							sherhMap.obiekt = tapMapID;
							sherhMap.map[sherhMap.obiekt] = new GMap2(document.getElementById(\"map_\"+sherhMap.obiekt));
							sherhMap.map[sherhMap.obiekt].addControl(new GSmallMapControl());
							sherhMap.map[sherhMap.obiekt].addControl(new GMapTypeControl());
							this.setcenter();
							this.geocoder = new GClientGeocoder();
							this.marker = new GMarker(this.center, {draggable: true});
							sherhMap.map[sherhMap.obiekt].addOverlay(sherhMap.marker);
							this.resultCoord(this.center.lat(),this.center.lng());
							sherhMap.addListnerMarker();
							sherhMap.addListnerMap();			
						}
					},
					mapID: false,
					obiekt: false,
					map: {},
					lat: 54.2238354,
					lng: -9.9876968,
					zoom: 11,
					center: false,
					setcenter: function(){
						this.center = new GLatLng(this.lat,this.lng);
						this.map[sherhMap.obiekt].setCenter(this.center, this.zoom);
					},
					geocoder: false,
					marker: false,
					point: false,
					addListnerMarker: function(){
						GEvent.addListener(sherhMap.marker, \"dragend\", function() {
							sherhMap.point = sherhMap.marker.getPoint();
							sherhMap.map[sherhMap.obiekt].panTo(sherhMap.point);
							sherhMap.resultCoord(sherhMap.point.lat(),sherhMap.point.lng());
						});	
					},
					addListnerMap: function(){
						GEvent.addListener(sherhMap.map[sherhMap.obiekt], \"moveend\", function() {
							sherhMap.map[sherhMap.obiekt].clearOverlays();
							sherhMap.center = sherhMap.map[sherhMap.obiekt].getCenter();
							sherhMap.marker = new GMarker(sherhMap.center, {draggable: true});
							sherhMap.map[sherhMap.obiekt].addOverlay(sherhMap.marker);
							sherhMap.resultCoord(sherhMap.center.lat(),sherhMap.center.lng());
			
							GEvent.addListener(sherhMap.marker, \"dragend\", function() {
								sherhMap.point = sherhMap.marker.getPoint();
								sherhMap.map[sherhMap.obiekt].panTo(sherhMap.point);
								sherhMap.resultCoord(sherhMap.point.lat(),sherhMap.point.lng());
							});
						});	
					},
					resultCoord: function(lat,lng){
						//$(\"lat\"+sherhMap.obiekt).attr(\"value\",lat);
						//$(\"lng\"+sherhMap.obiekt).attr(\"value\",lng);
						document.getElementById(\"lat\"+this.obiekt).value = lat;
						document.getElementById(\"lng\"+this.obiekt).value = lng;
					},
					showAddress: function (id) {
						address = $(\"#selectedAdressArea\"+id).text() + $(\"#tapAdres\"+id).val();
						if (sherhMap.geocoder) {
							
							sherhMap.geocoder.getLatLng(address,	function( point ) {
								if (!point) {
									alert(address + \" not found\");
								} else {
									sherhMap.resultCoord(point.lat(),point.lng());
									sherhMap.map[id].clearOverlays()
									sherhMap.map[id].setCenter(point, sherhMap.zoom);
									sherhMap.marker = new GMarker(point, {draggable: true});  
									sherhMap.map[id].addOverlay(sherhMap.marker);
					
									GEvent.addListener(sherhMap.marker, \"dragend\", function() {
										var pt = sherhMap.marker.getPoint();
										sherhMap.map[id].panTo(pt);
										document.getElementById(\"lat\"+sherhMap.obiekt).value = pt.lat();
										document.getElementById(\"lng\"+sherhMap.obiekt).value = pt.lng();
										//$(\"lat\"+sherhMap.id).attr(\"value\",pt.lat());
										//$(\"lng\"+sherhMap.id).attr(\"value\", pt.lng());
										sherhMap.resultCoord(pt.lat(),pt.lng());
									});
									GEvent.addListener(sherhMap.map[id], \"moveend\", function() {
										sherhMap.map[id].clearOverlays();
										sherhMap.center = sherhMap.map[id].getCenter();
										sherhMap.marker = new GMarker(sherhMap.center, {draggable: true});
										sherhMap.map[id].addOverlay(sherhMap.marker);
										sherhMap.resultCoord(sherhMap.center.lat(),sherhMap.center.lng());
					
										GEvent.addListener(sherhMap.marker, \"dragend\", function() {
											var pt = sherhMap.marker.getPoint();
											sherhMap.map[id].panTo(pt);
											//$(\"lat\"+sherhMap.obiekt).attr(\"value\",pt.lat());
											//$(\"lng\"+sherhMap.obiekt).attr(\"value\", pt.lng());
											document.getElementById(\"lat\"+sherhMap.obiekt).value = pt.lat();
											document.getElementById(\"lng\"+sherhMap.obiekt).value = pt.lng();
											sherhMap.resultCoord(pt.lat(),pt.lng());
										});
									});
								}
							});
						}
					}
				}
	
	$(document).ready(function() {
		sherhMap.init('-ID-'); // uruchomienie mapy	
		//sherhMap.showAddress('-ID-');
	});
	",$options = array('allowCache'=>true,'safe'=>true,'inline'=>false));
?>
<input class="wybrane-adresy-lokali" type="text" id="tapAdres-ID-" name="tapAdres" value="Intermarche Aleksandrów Łódzki , ul. Senatorska 4"/> <input class="szukaj-na-mapie-wg-adresu" type="button" onclick="sherhMap.showAddress('-ID-'); return false" value="Find on Map"/>
<div id="map_-ID-" style="width: 600px; height: 420px; display: block; "> </div>

<input type="text" name="tapLat" id="lat-ID-" value="54.2238354"/>
<input type="text" name="tapLng" id="lng-ID-" value="-9.9876968"/>